package com.service;

import com.entity.Weather;
import com.mapper.WeatherMapper;
import com.util.ChatsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service("WeatherService")
public class WeatherServiceImp implements WeatherService {

    @Autowired
    private WeatherMapper weatherMapper;

    @Override
    public ChatsResult getWeatherList() {
        int num = 0;
        List<Weather> weathers = weatherMapper.selectAllWeather();
        if (weathers != null) {
            num = weathers.size();
        }
        ChatsResult result = new ChatsResult(num);
        if (weathers != null) {
            String[] cellNames = result.getCellNames();
            BigDecimal[] cellValues = result.getCellValues();
            for (int i = 0; i < num; i++) {
                cellNames[i] = weathers.get(i).getCellName();
                cellValues[i] = weathers.get(i).getCellValue();
            }
        }

        return result;
    }
}
